package com.ruoyi.customer.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.customer.domain.bo.TCustomerInfoChangeBo;
import com.ruoyi.customer.domain.vo.TCustomerInfoChangeVo;
import com.ruoyi.customer.service.ITCustomerInfoChangeService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 客户信息变更记录
 *
 * @author ruoyi
 * @date 2023-12-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/customer/customerInfoChange")
public class TCustomerInfoChangeController extends BaseController {

    private final ITCustomerInfoChangeService iTCustomerInfoChangeService;

    /**
     * 查询客户信息变更记录列表
     */
    //@SaCheckPermission("customer:customerInfoChange:list")
    @GetMapping("/list")
    public TableDataInfo<TCustomerInfoChangeVo> list(TCustomerInfoChangeBo bo, PageQuery pageQuery) {
        return iTCustomerInfoChangeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出客户信息变更记录列表
     */
    //@SaCheckPermission("customer:customerInfoChange:export")
    @Log(title = "客户信息变更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TCustomerInfoChangeBo bo, HttpServletResponse response) {
        List<TCustomerInfoChangeVo> list = iTCustomerInfoChangeService.queryList(bo);
        ExcelUtil.exportExcel(list, "客户信息变更记录", TCustomerInfoChangeVo.class, response);
    }

    /**
     * 获取客户信息变更记录详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("customer:customerInfoChange:query")
    @GetMapping("/{id}")
    public R<TCustomerInfoChangeVo> getInfo(@NotNull(message = "主键不能为空")
                                            @PathVariable Long id) {
        return R.ok(iTCustomerInfoChangeService.queryById(id));
    }

    /**
     * 新增客户信息变更记录
     */
    //@SaCheckPermission("customer:customerInfoChange:add")
    @Log(title = "客户信息变更记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TCustomerInfoChangeBo bo) {
        return toAjax(iTCustomerInfoChangeService.insertByBo(bo));
    }

    /**
     * 修改客户信息变更记录
     */
    //@SaCheckPermission("customer:customerInfoChange:edit")
    @Log(title = "客户信息变更记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TCustomerInfoChangeBo bo) {
        return toAjax(iTCustomerInfoChangeService.updateByBo(bo));
    }

    /**
     * 删除客户信息变更记录
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("customer:customerInfoChange:remove")
    @Log(title = "客户信息变更记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iTCustomerInfoChangeService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 获取客户变成记录信息
     */
    //@SaCheckPermission("customer:customerInfoChange:remove")
    @PostMapping("/getCustomerChangeList")
    public R<List<TCustomerInfoChangeVo>> getCustomerChangeList(@RequestBody TCustomerInfoChangeBo bo) {
        return R.ok(iTCustomerInfoChangeService.getCustomerChangeList(bo));
    }
}
